package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.RPage;
import com.ruoyi.system.domain.vo.WOrderOpearaGoodVO;
import com.ruoyi.system.domain.vo.WOrderOpearaVO;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.IWOrderOpearaGoodService;
import com.ruoyi.system.service.IWOrderOpearaService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 物料订单操作记录Controller
 * 
 * @author ruoyi
 * @date 2021-12-05
 */
@Api( value="物料订单操作记录", tags="物料订单操作记录")
@RestController
@RequestMapping("/system/opeara")
public class WOrderOpearaController extends BaseController
{
    @Autowired
    private IWOrderOpearaService wOrderOpearaService;
    @Autowired
    private IWOrderOpearaGoodService wOrderOpearaGoodService;
    @Autowired
    private ISysUserService iSysUserService;
    
    
    @ApiOperation("小程序查询 盘点记录列表  也是来料列表")
    @GetMapping("/listSmall")
    public RPage<WOrderOpearaVO> listSmall(WOrderOpearaVO wOrderOpeara)
    {
    	wOrderOpeara.setType(1);
        startPage();
        wOrderOpeara.setStatus(3);
        List<WOrderOpearaVO> list = wOrderOpearaService.selectWOrderOpearaList(wOrderOpeara);
		return  getRPageTable(list);
    }
    @ApiOperation("小程序查询退货列表")
    @GetMapping("/listRefundSmall")
    public RPage<WOrderOpearaVO> listRefundSmall(WOrderOpearaVO wOrderOpeara)
    {
    	startPage();
    	List<WOrderOpearaVO> list = wOrderOpearaService.listRefundSmall(wOrderOpeara);
    	return  getRPageTable(list);
    }
    @ApiOperation("小程序查询退货详情接口")
    @GetMapping(value = "selectWOrderOpearaRefundSmallById/{id}")
    public R<WOrderOpearaVO>  selectWOrderOpearaRefundSmallById(@PathVariable("id") Long id)
    {
    	R<WOrderOpearaVO> selectWOrderOpearaById = wOrderOpearaService.selectWOrderOpearaById(id);
        return selectWOrderOpearaById;
    }
    
    @ApiOperation("小程序查询发料详情接口")
    @GetMapping(value = "selectWOrderOpearaSmallById/{id}")
    public R<WOrderOpearaVO>  selectWOrderOpearaSmallById(@PathVariable("id") Long id)
    {
    	R<WOrderOpearaVO> selectWOrderOpearaById = wOrderOpearaService.selectWOrderOpearaById(id);
        return selectWOrderOpearaById;
    }
    
    
    @ApiOperation("添加入库入库的退物料的, 传wOrderOpearaGoodList 对象")
    @PostMapping("/addreturn")
    public R<WOrderOpearaGoodVO> addreturn(@RequestBody WOrderOpearaVO wOrderOpearaVO)
    {
    	Long deptId = getDeptId();
    	wOrderOpearaVO.setDeptId(deptId);
    	wOrderOpearaVO.setCheckBy(getUsername());
    	wOrderOpearaVO.setCheckTime(new Date());
    	return wOrderOpearaService.addReturn(wOrderOpearaVO);
    }

    
    @ApiOperation("没入库退回的，全部退的")
    @GetMapping("/addReturnGoodsAll")
    public R returnGoodsAll(WOrderOpearaVO wOrderOpearaVO)
    {
        return wOrderOpearaGoodService.returnGoodsAll(wOrderOpearaVO);
    }
    
    @ApiOperation("添加发料入库的, 传wOrderOpearaGoodList 对象")
    @PostMapping("/addIn")
    public R<WOrderOpearaGoodVO> addIn(@RequestBody WOrderOpearaVO wOrderOpearaVO)
    {
    	wOrderOpearaVO.setCheckBy(getUsername());
    	wOrderOpearaVO.setCheckTime(new Date());
    	return wOrderOpearaService.addIn(wOrderOpearaVO);
    }

    @ApiOperation("添加发料接口")
    @PostMapping("addWOrderOpeara")
    public R addWOrderOpeara(@RequestBody WOrderOpearaVO wOrderOpearaVO)
    {
    	String username = getUsername();
    	wOrderOpearaVO.setCreateBy(username);
        return wOrderOpearaService.addWOrderOpeara(wOrderOpearaVO);
    }
    
    /**
     * 获取物料订单操作记录详细信息
     */
    @ApiOperation("发料详情接口")
    @GetMapping(value = "selectWOrderOpearaById/{id}")
    public R<WOrderOpearaVO>  selectWOrderOpearaById(@PathVariable("id") Long id)
    {
    	R<WOrderOpearaVO> selectWOrderOpearaById = wOrderOpearaService.selectWOrderOpearaById(id);
        return selectWOrderOpearaById;
    }
    
    @ApiOperation("根据客户查询这个工厂发料列表")
    @GetMapping("/listByFactoryAndCustomer")
    public RPage<WOrderOpearaVO> listByFactoryAndCustomer(WOrderOpearaVO wOrderOpeara)
    {
    	Long customerId = wOrderOpeara.getCustomerId();
    	if (customerId == null ) {
			return RPage.error("没传看客户id");
		}
    	SysUser selectUserById = iSysUserService.selectUserById(customerId);
    	wOrderOpeara.setDeptId(selectUserById.getDeptId());
        startPage();
        List<WOrderOpearaVO> list = wOrderOpearaService.selectWOrderOpearaList(wOrderOpeara);
		return  getRPageTable(list);
    }
    
    /**
     * 查询物料订单操作记录列表
     */
    @ApiOperation(" 查询物来订单操作记录列表  ，传订单id 查询这个订单的发料的列表")
    @GetMapping("/list")
    public RPage<WOrderOpearaVO> list(WOrderOpearaVO wOrderOpeara)
    {
        startPage();
        List<WOrderOpearaVO> list = wOrderOpearaService.selectWOrderOpearaList(wOrderOpeara);
		return  getRPageTable(list);
    }
    
    @ApiOperation(" 工厂查询来料订单列表 ")
    @GetMapping("/flist")
    public RPage<WOrderOpearaVO> flist(WOrderOpearaVO wOrderOpeara)
    {
    	
    	wOrderOpeara.setDeptId(getDeptId());
        startPage();
        wOrderOpeara.setType(1);
        List<WOrderOpearaVO> list = wOrderOpearaService.selectWOrderOpearaList(wOrderOpeara);
		return  getRPageTable(list);
    }

    
    @ApiOperation(" 客户查询来料订单列表 ")
    @GetMapping("/customerlist")
    public RPage<WOrderOpearaVO> customerlist(WOrderOpearaVO wOrderOpeara)
    {
    	
    	wOrderOpeara.setCustomerId(getUserId());
        startPage();
        List<WOrderOpearaVO> list = wOrderOpearaService.selectWOrderOpearaList(wOrderOpeara);
		return  getRPageTable(list);
    }
    
    
    
    
    

    
    
//    /**
//     * 导出物料订单操作记录列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:opeara:export')")
//    @Log(title = "物料订单操作记录", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(WOrderOpeara wOrderOpeara)
//    {
//        List<WOrderOpeara> list = wOrderOpearaService.selectWOrderOpearaList(wOrderOpeara);
//        ExcelUtil<WOrderOpeara> util = new ExcelUtil<WOrderOpeara>(WOrderOpeara.class);
//        return util.exportExcel(list, "物料订单操作记录数据");
//    }

   
}
